package com.jams.goodox.utils;

import android.content.Context;
import android.text.TextUtils;

import com.facebook.drawee.interfaces.DraweeController;
import com.facebook.imagepipeline.request.ImageRequest;
import com.lvman.configs.instrumentation.ConfigConstants;
import com.lvman.configs.instrumentation.InstrumentedDraweeView;
import com.lvman.configs.instrumentation.PerfListener;

public class FrescoUtils {
    // 生成img 并load Url
    public static void loadUrl(Context context, InstrumentedDraweeView img, String url) {
        if (TextUtils.isEmpty(url)) {
            url = "www";
        }
        img.initInstrumentation(url, new PerfListener());
        ImageRequest imageRequest = ConfigConstants.getImageRequest(img, url);
        DraweeController draweeController = ConfigConstants.getDraweeController(imageRequest, img);
        img.setController(draweeController);
    }


    public static void loadUrl(Context context, InstrumentedDraweeView img, String url, int x , int y) {
        if (TextUtils.isEmpty(url)) {
            url = "www";
        }
        img.initInstrumentation(url, new PerfListener());
        ImageRequest imageRequest = ConfigConstants.getImageRequest(img, url,x,y);
        DraweeController draweeController = ConfigConstants.getDraweeController(imageRequest, img);
        img.setController(draweeController);
    }


    public static void loadUrl(Context context, InstrumentedDraweeView img, String url, PerfListener listener) {
        if (TextUtils.isEmpty(url)) {
            url = "www";
        }
       // img.setHierarchy(ConfigConstants.getGenericDraweeHierarchy(context));
        img.initInstrumentation(url, listener);
        ImageRequest imageRequest = ConfigConstants.getImageRequest(img, url);
        img.setController(ConfigConstants.getDraweeController(imageRequest, img));
    }
}
